<template>
    <vol-box :lazy="true" v-model="model"  title="选择物料" :width="1100" :padding="5">
      <div>
        <products ref="product"></products>
      </div>
      <template #footer>
        <div> 
            <el-button type="primary"  @click="onSelect">选中数据</el-button>
            <el-button type="default" size="small" @click="closeModel" >点击关闭弹出框</el-button >
        </div>
       
    </template>
        
    </vol-box>
  </template>

  <script>
  import VolBox from "@/components/basic/VolBox.vue";
  import products from '@/views/dbmethod/product/products';
  export default {
    emits: ["parentCall"],
    components: {
      "vol-box": VolBox,
      products,
     // VolTable,
    },
    methods: {},
    data() {
      return {
        model: false, //弹出框      
      };
    },
    methods: {
      open() {
        //打开主表选择数据
        this.model = true;
  
        //打开时刷新界面数据(2022.12.06)
        this.$nextTick(() => {
          this.$refs.product && this.$refs.product.$refs.grid.search();
        });
      },
      openDetail() {
        //打明细表批量选择
        this.detailModel = true;
  
        //刷新表格的数据
        this.$nextTick(() => {
          this.$refs.detailTable?.load(null, true);
        });
      },
      onSelect() {
        //主表的选择数据回写到主表的表单上
        let rows = this.$refs.product.$refs.grid.getSelectRows();
        if (!rows.length) {
          return this.$message.error("请选择数据");
        }
        this.$emit("parentCall", ($parent) => {
          $parent.editFormFields.ProductCode= rows[0].ProductCode;
          $parent.editFormFields.ProductName = rows[0].ProductName;
          $parent.editFormFields.DrawNo = rows[0].DrawNo;
          $parent.editFormFields.ProductID = rows[0].ID;
          this.model = false;
        });
      },
      closeModel(){
        this.model=false;
    },
     
  }
}
  </script>
  
  <style lang="less" scoped>
  .search-form {
    display: flex;
    padding: 10px;
    line-height: 34px;
  
    button {
      margin-left: 10px;
    }
  }
  </style>
  